#!/bin/bash 
set -e


TMP=${TMP:-/tmp/work}
LOG=${LOG:-$HOME/logs/stage4}
SRC=${SRC:-/sources}

name=cpio
version=2.13

rm -rf $TMP
mkdir -p $TMP $LOG

tar xf $SRC/$name-$version.tar.bz2 -C $TMP

{ time \
   {

    cd $TMP/$name-$version
    
	sed -i '/The name/,+2 d' src/global.c

	./configure --prefix=/usr \
	            --bindir=/bin \
	            --enable-mt   \
	            --with-rmt=/usr/libexec/rmt
	make
	makeinfo --html            -o doc/html      doc/cpio.texi
	makeinfo --html --no-split -o doc/cpio.html doc/cpio.texi
	makeinfo --plaintext       -o doc/cpio.txt  doc/cpio.texi

	make install
	install -v -m755 -d /usr/share/doc/$name-$version/html
	install -v -m644    doc/html/* \
	                    /usr/share/doc/$name-$version/html
	install -v -m644    doc/cpio.{html,txt} \
	                    /usr/share/doc/$name-$version

    }
} 2>&1 | tee $name.log
    
[ $PIPESTATUS = 0 ] && mv $name.log $LOG || exit $PIPESTATUS

rm -fr $TMP
